package com.zjsru.plan2024.oneday;

/**
 * 832. 翻转图像
 *
 * @Author: cookLee
 * @Date: 2024-11-13
 */
public class FlipAndInvertImage {

    /**
     * 主
     * \
     * 输入：image = [[1,1,0],[1,0,1],[0,0,0]]
     * 输出：[[1,0,0],[0,1,0],[1,1,1]]
     * 解释：首先翻转每一行: [[0,1,1],[1,0,1],[0,0,0]]；
     * 然后反转图片: [[1,0,0],[0,1,0],[1,1,1]]
     * \
     * 输入：image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
     * 输出：[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
     * 解释：首先翻转每一行: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]；
     * 然后反转图片: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
     * \
     *
     * @param args args
     */
    public static void main(String[] args) {
        FlipAndInvertImage flipAndInvertImage = new FlipAndInvertImage();
        int[][] image = new int[][]{{1, 1, 0}, {1, 0, 1}, {0, 0, 0}};
        System.out.println(flipAndInvertImage.flipAndInvertImage(image));

    }

    public int[][] flipAndInvertImage(int[][] image) {
        int len = image.length;
        for (int i = 0; i < len; i++) {
            int left = 0;
            int right = image[i].length - 1;
            while (left <= right) {
                int temp = image[i][left];
                image[i][left] = image[i][right] ^ 1;
                image[i][right] = temp ^ 1;
                left++;
                right--;
            }
        }
        return image;
    }


}
